package com.study.test;

import javax.swing.*;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

public class MyJFrame3 extends JFrame implements KeyListener {




    public MyJFrame3() {
        //设置界面的宽高
        this.setSize(603, 680);

        //设置界面的标题
        this.setTitle("拼图游戏v1.0");

        //设置界面置顶
        this.setAlwaysOnTop(true);

        //设置界面居中
        this.setLocationRelativeTo(null);

        //设置界面关闭
        this.setDefaultCloseOperation(3);

        //取消默认的居中放置
        this.setLayout(null);





        //给按钮绑定键盘事件
        this.addKeyListener(this);







        //显示界面
        this.setVisible(true);


    }


    @Override
    public void keyTyped(KeyEvent e) {
        System.out.println("键盘按下了");

    }

    //按下不松会重复调用
    @Override
    public void keyPressed(KeyEvent e) {
        System.out.println("键盘被按下不松");

    }

    @Override
    public void keyReleased(KeyEvent e) {
        System.out.println("键盘被松开了");
        int code=e.getKeyCode();
        System.out.println(code);

    }
}
